load("@rules_proto_grpc//:defs.bzl", "proto_plugin")
load("@rules_proto_grpc_python_pip_deps//:requirements.bzl", "requirement")
load("@rules_python//python/entry_points:py_console_script_binary.bzl", "py_console_script_binary")
load("@rules_python//python/pip_install:requirements.bzl", "compile_pip_requirements")

compile_pip_requirements(
    name = "requirements",
    extra_args = [
        "--generate-hashes",
    ],
    requirements_in = "requirements.in",
    requirements_txt = "requirements.txt",
    tags = [
        "manual",
    ],
)

proto_plugin(
    name = "proto_plugin",
    exclusions = [
        "google/protobuf",
    ],
    outputs = ["{protopath|python}_pb2.py"],
    protoc_plugin_name = "python",
    visibility = ["//visibility:public"],
)

proto_plugin(
    name = "grpc_plugin",
    exclusions = [
        "google/protobuf",
    ],
    outputs = ["{protopath|python_grpc}_pb2_grpc.py"],
    tool = "@grpc//src/compiler:grpc_python_plugin",
    visibility = ["//visibility:public"],
)

py_console_script_binary(
    name = "grpclib_plugin_bin",
    pkg = requirement("grpclib"),
    script = "protoc-gen-grpclib_python",
    deps = [
        requirement("protobuf"),
    ],
)

proto_plugin(
    name = "grpclib_plugin",
    outputs = ["{protopath|python}_grpc.py"],
    tool = "//:grpclib_plugin_bin",
    visibility = ["//visibility:public"],
)

proto_plugin(
    name = "pyi_plugin",
    exclusions = [
        "google/protobuf",
    ],
    outputs = ["{protopath|python}_pb2.pyi"],
    protoc_plugin_name = "pyi",
    visibility = ["//visibility:public"],
)
